diff --git a/opt/atlassian/bitbucket/bin/_start-webapp.sh b/opt/atlassian/bitbucket/bin/_start-webapp.sh
index d5b493d..e74a17c 100755
--- a/opt/atlassian/bitbucket/bin/_start-webapp.sh
+++ b/opt/atlassian/bitbucket/bin/_start-webapp.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/bash
 
 if [ -z "$BIN_DIR" ] || [ -z "$INST_DIR" ] || [ -z "$BITBUCKET_HOME" ]; then
     echo "$0 is not intended to be run directly. Run start-bitbucket.sh instead"
@@ -10,16 +10,16 @@ fi
 # environment variable has been set in the environment of the user running this script, uncommenting the below
 # will override that.
 #
-#JVM_SUPPORT_RECOMMENDED_ARGS=
+JVM_SUPPORT_RECOMMENDED_ARGS="-Datlassian.plugins.enable.wait=300 -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions"
 
 # The following 2 settings control the minimum and maximum memory allocated to the Java virtual machine.
 # For larger instances, the maximum amount will need to be increased.
 #
 if [ -z "${JVM_MINIMUM_MEMORY}" ]; then
-    JVM_MINIMUM_MEMORY=512m
+    JVM_MINIMUM_MEMORY="2048m"
 fi
 if [ -z "${JVM_MAXIMUM_MEMORY}" ]; then
-    JVM_MAXIMUM_MEMORY=1g
+    JVM_MAXIMUM_MEMORY="2048m"
 fi
 
 # This setting controls the time (in ms) after which idle JNDI connections are removed from the connection pool
@@ -31,7 +31,7 @@ fi
 # Uncommenting the following will set the umask for the webapp. It can be used to override the default
 # settings for the service user if they are not sufficiently secure.
 #
-# umask 0027
+umask 0027
 
 UMASK=$(umask)
 UMASK_SYMBOLIC=$(umask -S)
@@ -104,10 +104,10 @@ BITBUCKET_ARGS="-Datlassian.standalone=BITBUCKET -Dbitbucket.home=$BITBUCKET_HOM
 JNDI_ARGS="-Dcom.sun.jndi.ldap.connect.pool.timeout=$JNDI_CONNECTION_POOL_TIMEOUT"
 JVM_FILE_ENCODING_ARGS="-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8"
 JVM_JAVA_ARGS="-Djava.io.tmpdir=$BITBUCKET_HOME/tmp -Djava.library.path=$JVM_LIBRARY_PATH --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.naming/com.sun.jndi.ldap=ALL-UNNAMED"
-JVM_MEMORY_ARGS="-Xms$JVM_MINIMUM_MEMORY -Xmx$JVM_MAXIMUM_MEMORY -XX:+UseG1GC"
+JVM_MEMORY_ARGS="-Xms$JVM_MINIMUM_MEMORY -Xmx$JVM_MAXIMUM_MEMORY -XX:ReservedCodeCacheSize=512m -XX:+UseZGC -XX:ZCollectionInterval=5 -XX:ZAllocationSpikeTolerance=5 -XX:+ExplicitGCInvokesConcurrent"
 JVM_REQUIRED_ARGS="$JVM_MEMORY_ARGS $JVM_FILE_ENCODING_ARGS $JVM_JAVA_ARGS"
 
-JAVA_OPTS="-classpath $INST_DIR/app $JAVA_OPTS $BITBUCKET_ARGS $JNDI_ARGS $JMX_OPTS $JVM_REQUIRED_ARGS $JVM_SUPPORT_RECOMMENDED_ARGS"
+JAVA_OPTS="-classpath $INST_DIR/app $JAVA_OPTS $BITBUCKET_ARGS $JNDI_ARGS $JMX_OPTS $JVM_SUPPORT_RECOMMENDED_ARGS $JVM_REQUIRED_ARGS"
 LAUNCHER="com.atlassian.bitbucket.internal.launcher.BitbucketServerLauncher"
 
 echo -e "\nStarting Bitbucket webapp at http://localhost:7990"
diff --git a/opt/atlassian/bitbucket/bin/set-bitbucket-home.sh b/opt/atlassian/bitbucket/bin/set-bitbucket-home.sh
index 1e04fe1..ac546fa 100755
--- a/opt/atlassian/bitbucket/bin/set-bitbucket-home.sh
+++ b/opt/atlassian/bitbucket/bin/set-bitbucket-home.sh
@@ -1,8 +1,13 @@
+#!/bin/bash
+
 # One way to set the BITBUCKET_HOME path is here via this variable.  Simply uncomment it and set a valid path like
 # /bitbucket/home.  You can of course set it outside in the command terminal; that will also work.
 #
 if [ -z "$BITBUCKET_HOME" ]; then
-    BITBUCKET_HOME=
+    BITBUCKET_HOME="/var/atlassian/application-data/bitbucket"
+fi
+if [ -z "$BITBUCKET_CATALINA" ]; then
+    BITBUCKET_CATALINA="/opt/atlassian/bitbucket"
 fi
 
 # When upgrading from the packaged distribution BITBUCKET_HOME may not be set. Fallback to legacy STASH_HOME
@@ -31,4 +36,5 @@ if [ $? -eq 0 ]; then
     return 1
 fi
 
-export BITBUCKET_HOME
\ No newline at end of file
+export BITBUCKET_HOME
+export BITBUCKET_CATALINA
diff --git a/opt/atlassian/bitbucket/bin/set-bitbucket-user.sh b/opt/atlassian/bitbucket/bin/set-bitbucket-user.sh
index aa5daab..ed986ea 100755
--- a/opt/atlassian/bitbucket/bin/set-bitbucket-user.sh
+++ b/opt/atlassian/bitbucket/bin/set-bitbucket-user.sh
@@ -1,9 +1,11 @@
-if [ -n "${BITBUCKET_USER}" ]; then
+#!/bin/bash
+
+if [ -n "${BITBUCKET_OWNER}" ]; then
     return
 fi
 
 # START INSTALLER MAGIC ! DO NOT EDIT !
-BITBUCKET_USER="" ##
+BITBUCKET_OWNER="bitbucket"
 # END INSTALLER MAGIC ! DO NOT EDIT !
 
-export BITBUCKET_USER
+export BITBUCKET_OWNER
diff --git a/opt/atlassian/bitbucket/bin/set-jre-home.sh b/opt/atlassian/bitbucket/bin/set-jre-home.sh
index d747ae3..53710e1 100755
--- a/opt/atlassian/bitbucket/bin/set-jre-home.sh
+++ b/opt/atlassian/bitbucket/bin/set-jre-home.sh
@@ -1,11 +1,30 @@
-# Uncomment and edit the line below to define JRE_HOME.
-# If you use the Bitbucket installer, this value will be automatically set to point to the bundled JRE.
-# Once a value is set here, existing JRE_HOME and JAVA_HOME values set in the environment will be overridden and ignored.
-# JRE_HOME=
+#!/bin/bash
+
+# Set JAVA_HOME to working JDK or JRE
+# If not set we'll try to guess the JAVA_HOME
+# from java binary if on the PATH
+if [ -z "$JAVA_HOME" ]; then
+    JAVA_BINARY="`which java 2>/dev/null || type java 2>&1`"
+    while [ -h "$JAVA_BINARY" ]; do
+        ls=`ls -ld "$JAVA_BINARY"`
+        link=`expr "$ls" : '.*-> \(.*\)$'`
+        if expr "$link" : '/.*' > /dev/null; then
+            JAVA_BINARY="$link"
+        else
+            JAVA_BINARY="`dirname $JAVA_BINARY`/$link"
+        fi
+    done
+    test -x "$JAVA_BINARY" && JAVA_HOME="`dirname $JAVA_BINARY`"
+    test ".$JAVA_HOME" != . && JAVA_HOME=`cd "$JAVA_HOME/.." >/dev/null; pwd`
+else
+    JAVA_BINARY="$JAVA_HOME/bin/java"
+fi
 
-# Otherwise, use an existing installed JDK defined by JAVA_HOME
 if [ -z "$JRE_HOME" ]; then
-    if [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/jre/bin/java" ]; then
+    if [ -z "$JAVA_HOME" ]; then
+        # If JRE_HOME and JAVA_HOME are not defined, edit this line to define JRE_HOME
+        JRE_HOME=
+    elif [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/jre/bin/java" ]; then
         # If JAVA_HOME points to a valid JDK, use its JRE
         JRE_HOME="$JAVA_HOME/jre"
     elif [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ]; then
diff --git a/opt/atlassian/bitbucket/bin/start-bitbucket.sh b/opt/atlassian/bitbucket/bin/start-bitbucket.sh
index e54ba17..19f5702 100755
--- a/opt/atlassian/bitbucket/bin/start-bitbucket.sh
+++ b/opt/atlassian/bitbucket/bin/start-bitbucket.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/bash
 
 # Resolve any links in $0 to get the real path
 SELF="$0"
@@ -53,15 +53,15 @@ else
     LAUNCH_CMD=start
 fi
 
-if [ -z "$BITBUCKET_USER" ] || [ $(id -un) == "$BITBUCKET_USER" ]; then
+if [ -z "$BITBUCKET_OWNER" ] || [ $(id -un) == "$BITBUCKET_OWNER" ]; then
     echo "Starting Atlassian Bitbucket as the current user"
     $BIN_DIR/_start-webapp.sh $LAUNCH_CMD
 elif [ $UID -ne 0 ]; then
-    echo Atlassian Bitbucket has been installed to run as $BITBUCKET_USER. Use "sudo -u $BITBUCKET_USER $0"
+    echo Atlassian Bitbucket has been installed to run as $BITBUCKET_OWNER. Use "sudo -u $BITBUCKET_OWNER $0"
     echo to start as that user.
     exit 1
 else
-    echo "Starting Atlassian Bitbucket as dedicated user $BITBUCKET_USER"
+    echo "Starting Atlassian Bitbucket as dedicated user $BITBUCKET_OWNER"
 
     if [ -x "/sbin/runuser" ]; then
         SU="/sbin/runuser"
@@ -69,7 +69,7 @@ else
         SU="su"
     fi
 
-    $SU -l $BITBUCKET_USER <<EOS
+    $SU -l $BITBUCKET_OWNER <<EOS
         # Copy over the environment, the poor man's way
         export BIN_DIR="$BIN_DIR"
         export BITBUCKET_HOME="$BITBUCKET_HOME"
@@ -94,4 +94,4 @@ else
 
         $BIN_DIR/_start-webapp.sh $LAUNCH_CMD
 EOS
-fi
\ No newline at end of file
+fi
diff --git a/opt/atlassian/bitbucket/bin/stop-bitbucket.sh b/opt/atlassian/bitbucket/bin/stop-bitbucket.sh
index 433613c..69e972b 100755
--- a/opt/atlassian/bitbucket/bin/stop-bitbucket.sh
+++ b/opt/atlassian/bitbucket/bin/stop-bitbucket.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/bash
 
 # Resolve any links in $0 to get the real path
 SELF="$0"
@@ -22,18 +22,18 @@ if [ -z "$BITBUCKET_HOME" ]; then
     exit 1
 fi
 
-if [ -z "$BITBUCKET_USER" ] || [ $(id -un) == "$BITBUCKET_USER" ]; then
+if [ -z "$BITBUCKET_OWNER" ] || [ $(id -un) == "$BITBUCKET_OWNER" ]; then
     echo "Stopping Atlassian Bitbucket as the current user"
 
     # Stop webapp first. The stop script relies on a PID file generated by
     # the paired start script
     $BIN_DIR/_stop-webapp.sh
 elif [ $UID -ne 0 ]; then
-    echo Atlassian Bitbucket has been installed to run as $BITBUCKET_USER, and can only be stopped by that
-    echo user. Use "sudo -u $BITBUCKET_USER $0" to stop Bitbucket.
+    echo Atlassian Bitbucket has been installed to run as $BITBUCKET_OWNER, and can only be stopped by that
+    echo user. Use "sudo -u $BITBUCKET_OWNER $0" to stop Bitbucket.
     exit 1
 else
-    echo "Stopping Atlassian Bitbucket as dedicated user $BITBUCKET_USER"
+    echo "Stopping Atlassian Bitbucket as dedicated user $BITBUCKET_OWNER"
 
     if [ -x "/sbin/runuser" ]; then
         SU="/sbin/runuser"
@@ -41,7 +41,7 @@ else
         SU="su"
     fi
 
-    $SU -l $BITBUCKET_USER <<EOS
+    $SU -l $BITBUCKET_OWNER <<EOS
         # Copy over the environment, the poor man's way
         export BITBUCKET_HOME="$BITBUCKET_HOME"
         export BIN_DIR="$BIN_DIR"
@@ -52,4 +52,4 @@ else
 
         $BIN_DIR/_stop-webapp.sh
 EOS
-fi
\ No newline at end of file
+fi
