diff --git a/src/snek/static/app.js b/src/snek/static/app.js
index f26919e..29aedb2 100644
--- a/src/snek/static/app.js
+++ b/src/snek/static/app.js
@@ -7,7 +7,9 @@
 
 // MIT License
 
-class RESTClient {
+import { Schedule } from './schedule.js';
+
+export class RESTClient {
     debug = false;
 
     async get(url, params = {}) {
@@ -43,7 +45,7 @@ class RESTClient {
     }
 }
 
-class EventHandler {
+export class EventHandler {
     constructor() {
         this.subscribers = {};
     }
@@ -58,7 +60,7 @@ class EventHandler {
     }
 }
 
-class Chat extends EventHandler {
+export class Chat extends EventHandler {
     constructor() {
         super();
         this._url = window.location.hostname === 'localhost' ? 'ws://localhost/chat.ws' : 'wss://' + window.location.hostname + '/chat.ws';
@@ -132,7 +134,7 @@ class Chat extends EventHandler {
     }
 }
 
-class Socket extends EventHandler {
+export class Socket extends EventHandler {
     ws = null;
     isConnected = null;
     isConnecting = null;
@@ -259,7 +261,7 @@ class Socket extends EventHandler {
     }
 }
 
-class NotificationAudio {
+export class NotificationAudio {
     constructor(timeout = 500) {
         this.schedule = new Schedule(timeout);
     }
@@ -284,7 +286,7 @@ class NotificationAudio {
     }
 }
 
-class App extends EventHandler {
+export class App extends EventHandler {
     rest = new RESTClient();
     ws = null;
     rpc = null;
@@ -366,4 +368,4 @@ class App extends EventHandler {
     }
 }
 
-const app = new App();
+export const app = new App();
diff --git a/src/snek/static/schedule.js b/src/snek/static/schedule.js
index 36ae803..7e3add5 100644
--- a/src/snek/static/schedule.js
+++ b/src/snek/static/schedule.js
@@ -9,7 +9,7 @@
 // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-class Schedule {
+export class Schedule {
   constructor(msDelay = 100) {
     this.msDelay = msDelay;
     this._once = false;
diff --git a/src/snek/templates/app.html b/src/snek/templates/app.html
index 60109de..5e30845 100644
--- a/src/snek/templates/app.html
+++ b/src/snek/templates/app.html
@@ -9,12 +9,11 @@
   <!-- 
   <script src="/push.js"></script>
   -->
-  <script src="/fancy-button.js"></script>
-  <script src="/upload-button.js"></script>
-  <script src="/generic-form.js"></script>
-  <script src="/html-frame.js"></script>
-  <script src="/schedule.js"></script>
-  <script src="/app.js"></script>
+  <script src="/fancy-button.js" type="module"></script>
+  <script src="/upload-button.js" type="module"></script>
+  <script src="/generic-form.js" type="module"></script>
+  <script src="/html-frame.js" type="module"></script>
+  <script src="/app.js" type="module"></script>
   <link rel="stylesheet" href="/base.css">
 
   <link rel="icon" type="image/png" href="/image/snek1.png" sizes="32x32">
diff --git a/src/snek/templates/base.html b/src/snek/templates/base.html
index d93b568..a7cc1c5 100644
--- a/src/snek/templates/base.html
+++ b/src/snek/templates/base.html
@@ -12,13 +12,13 @@
 
     <title>{% block title %}Snek chat by Molodetz{% endblock %}</title>
 
-    <script src="/app.js"></script>
-    <script src="/message-list.js"></script>
+    <script src="/app.js"  type="module"></script>
+    <script src="/message-list.js" type="module"></script>
     <style>{{ highlight_styles }}</style>
     <link rel="stylesheet" href="/style.css">
-    <script src="/fancy-button.js"></script>
-    <script src="/html-frame.js"></script>
-    <script src="/generic-form.js"></script>
+    <script src="/fancy-button.js" type="module"></script>
+    <script src="/html-frame.js" type="module"></script>
+    <script src="/generic-form.js" type="module"></script>
     <link rel="stylesheet" href="/html-frame.css">
 
     {% block head %}
diff --git a/src/snek/templates/search_user.html b/src/snek/templates/search_user.html
index 453f7e3..cf35d0d 100644
--- a/src/snek/templates/search_user.html
+++ b/src/snek/templates/search_user.html
@@ -35,7 +35,8 @@
 
     </div>
 </section>
-<script>
+<script type="module">
+    import { app } from "/app.js";
 
     document.querySelector("[name=query]").focus();
 
diff --git a/src/snek/templates/threads.html b/src/snek/templates/threads.html
index 73c256a..ae71c6f 100644
--- a/src/snek/templates/threads.html
+++ b/src/snek/templates/threads.html
@@ -24,7 +24,8 @@
     <chat-window style="display:none" class="chat-area"></chat-window>
 </section>
 
-<script>
+<script type="module">
+    import { app } from "/app.js";
 
     function updateTimes() {
         document.querySelectorAll(".time").forEach((time) => {
diff --git a/src/snek/templates/web.html b/src/snek/templates/web.html
index e58af53..e1e443b 100644
--- a/src/snek/templates/web.html
+++ b/src/snek/templates/web.html
@@ -19,7 +19,9 @@
     </div>
 </section>
 
-<script>
+<script type="module">
+    import { app } from "/app.js";
+
     const channelUid = "{{ channel.uid.value }}";
 
     function getInputField(){
@@ -120,6 +122,8 @@
         loadExtra();
     });
 
+    let lastMessage
+
     function updateLayout(doScrollDown) {
         const messagesContainer = document.querySelector(".chat-messages");
         updateTimes();
@@ -134,7 +138,7 @@
         });
         lastMessage = messagesContainer.querySelector(".message:last-child");
         if (doScrollDown) { 
-            lastMessage.scrollIntoView({ inline: "nearest" });
+            lastMessage?.scrollIntoView({ inline: "nearest" });
         }
     }
 
@@ -171,7 +175,7 @@
         }
         
         const messagesContainer = document.querySelector(".chat-messages");
-        const lastMessage = messagesContainer.querySelector(".message:last-child"); 
+        lastMessage = messagesContainer.querySelector(".message:last-child");
         const doScrollDownBecauseLastMessageIsVisible = !lastMessage || isElementVisible(lastMessage);
 
         const message = document.createElement("div");