Index: pages/api/roulette/calculateWinnings.js
===================================================================
--- pages/api/roulette/calculateWinnings.js	(revision 433e0c5f4289ea953d6d2c2d010c6bd651bd0c8f)
+++ pages/api/roulette/calculateWinnings.js	(revision 433e0c5f4289ea953d6d2c2d010c6bd651bd0c8f)
@@ -0,0 +1,49 @@
+export function getWinningBets(magicNumber) {
+    let winningBets = [];
+    winningBets.push(magicNumber);
+    
+    if (magicNumber != 0) {
+        if ((magicNumber <= 9 && magicNumber % 2 == 1) || (magicNumber > 10 && magicNumber <= 18 && magicNumber % 2 == 0) ||
+            (magicNumber > 19 && magicNumber <= 27 && magicNumber % 2 == 1) || (magicNumber > 27 && magicNumber % 2 == 0)) {
+
+            winningBets.push('Red');
+        }
+        else {
+            winningBets.push('Black');
+        }
+
+        if (magicNumber % 2 === 0)      winningBets.push('Even');
+        else                            winningBets.push('Odd');
+
+        if (magicNumber <= 12)          winningBets.push('1-12');
+        else if (magicNumber <= 24)     winningBets.push('13-24');
+        else                            winningBets.push('25-36');
+
+        if (magicNumber <= 18)          winningBets.push('1-18');
+        else                            winningBets.push('19-36');
+
+        if (magicNumber % 3 === 0)      winningBets.push('Remainder3');
+        else if (magicNumber % 3 === 2) winningBets.push('Remainder2');
+        else                            winningBets.push('Remainder1');
+    }
+
+    return winningBets;
+}
+
+export function calculateWinnings(player) {
+    if (player.outcome === 'lost') return 0;
+
+    let bets = player.whichBets;
+    let bet = player.betAmount;
+
+    if (bets[0] === 'Even' || bets[0] === 'Odd') return 2 * bet;
+    else if (bets[0] === 'Red' || bets[0] === 'Black') return 2 * bet;
+    else if (bets[0].includes('Remainder')) return 3 * bet;
+    else if (bets[0] === '1-12' || bets[0] === '13-24' || bets[0] === '25-36') return 3 * bet;
+    else if (bets[0] === '1-18' || bets[0] === '19-36') return 2 * bet;
+    else if (bets.length === 4) return 9 * bet;
+    else if (bets.length === 2) return 18 * bet;
+    else if (bets.length === 1) return 36 * bet;
+
+    return 0;
+}
Index: pages/api/roulette/gameStates.js
===================================================================
--- pages/api/roulette/gameStates.js	(revision 433e0c5f4289ea953d6d2c2d010c6bd651bd0c8f)
+++ pages/api/roulette/gameStates.js	(revision 433e0c5f4289ea953d6d2c2d010c6bd651bd0c8f)
@@ -0,0 +1,113 @@
+import { calculateWinnings } from './calculateWinnings'
+
+import { game } from '../postgre/index'
+
+import axios from 'axios';
+
+export let samplePlayer = {
+    session_id: '',
+    name: '',
+    whichBets: [],
+    coinPlaced: {
+        x: -1,
+        y: -1,                
+    },
+    credits: -1,
+    betAmount: 0,
+    wonAmount: 0,
+    status: '_1_',
+    outcome: 'none',
+    gotResults: false,
+}
+
+export function resetGame() {
+    game.magicNumber = -1;
+    game.winningBets = [];
+    game.status = '_1_ongoing_timer';
+
+    game.players.forEach(player => {
+        player.whichBets = [];
+        player.betAmount = 0;
+        player.wonAmount = 0;
+        player.coinPlaced = {
+            x: -1,
+            y: -1,                
+        },
+        player.outcome = 'none';
+        player.status = '_1_no_placed_bet';
+        player.gotResults = false;
+    })
+}
+
+export function updateGameWithWinners() {
+    for (let i = 0; i < game.players.length; i++) {
+        const player = game.players[i];
+
+        let playerWon = false;
+        player.whichBets.forEach(bet => {
+            if (game.winningBets.indexOf(bet) !== -1) {
+                playerWon = true;
+            }
+        })
+
+        if (playerWon) {
+            player.outcome = 'won';
+        }
+        else {
+            player.outcome = 'lost';
+        }
+
+        player.wonAmount = calculateWinnings(player);
+
+        axios.get(`${process.env.HOME_URL}/api/postgre/?action=add_credits&session_id=${player.session_id}&credits=${player.wonAmount}&game=roulette&outcome=${player.outcome}`).then(postgreRes => {
+            if (postgreRes.data?.success) {
+                player.credits = postgreRes.data?.credits;
+            }
+        });
+    }
+}
+
+export function addPlayer(session_id, name) {
+    if (game.players.map(e=>e.session_id).indexOf(session_id) === -1) {
+        game.players.push({
+            session_id: session_id,
+            name: name,
+            whichBets: [],
+            coinPlaced: {
+                x: -1,
+                y: -1,                
+            },
+            credits: -1,
+            betAmount: 0,
+            wonAmount: 0,
+            status: '_1_no_placed_bet',
+            outcome: 'none',
+            gotResults: false,
+        })
+    }
+}
+
+export function getPlayer(session_id) {
+    const playerIdx = game.players.map(e=>e.session_id).indexOf(session_id);
+
+    if (playerIdx !== -1) {
+        return {
+            success: true,
+            player: game.players[playerIdx],
+        }
+    }
+
+    return {
+        success: false,
+        player: {...samplePlayer},
+    };
+}
+
+export function restrictGameInfo() {
+    const restrictedPlayers = game.players.map(player=>({...player, session_id: ""}))
+
+    return {
+        ...game,
+        players: restrictedPlayers,
+    }
+}
Index: pages/api/roulette/index.js
===================================================================
--- pages/api/roulette/index.js	(revision e9f11ac9f7bd22275a5c60c88cfbc767f040a8e6)
+++ pages/api/roulette/index.js	(revision 433e0c5f4289ea953d6d2c2d010c6bd651bd0c8f)
@@ -5,116 +5,7 @@
 require('dotenv').config();
 
-let samplePlayer = {
-    session_id: '',
-    name: '',
-    whichBets: [],
-    coinPlaced: {
-        x: -1,
-        y: -1,                
-    },
-    credits: -1,
-    betAmount: 0,
-    wonAmount: 0,
-    status: '_1_',
-    outcome: 'none',
-    gotResults: false,
-}
+import { resetGame, updateGameWithWinners, addPlayer, getPlayer, restrictGameInfo } from './gameStates'
 
-function getWinningBets(magicNumber) {
-    let winningBets = [];
-    winningBets.push(magicNumber);
-    
-    if (magicNumber != 0) {
-        if ((magicNumber <= 9 && magicNumber % 2 == 1) || (magicNumber > 10 && magicNumber <= 18 && magicNumber % 2 == 0) ||
-            (magicNumber > 19 && magicNumber <= 27 && magicNumber % 2 == 1) || (magicNumber > 27 && magicNumber % 2 == 0)) {
-
-            winningBets.push('Red');
-        }
-        else {
-            winningBets.push('Black');
-        }
-
-        if (magicNumber % 2 === 0)      winningBets.push('Even');
-        else                            winningBets.push('Odd');
-
-        if (magicNumber <= 12)          winningBets.push('1-12');
-        else if (magicNumber <= 24)     winningBets.push('13-24');
-        else                            winningBets.push('25-36');
-
-        if (magicNumber <= 18)          winningBets.push('1-18');
-        else                            winningBets.push('19-36');
-
-        if (magicNumber % 3 === 0)      winningBets.push('Remainder3');
-        else if (magicNumber % 3 === 2) winningBets.push('Remainder2');
-        else                            winningBets.push('Remainder1');
-    }
-
-    return winningBets;
-}
-
-function updateGameWithWinners() {
-    for (let i = 0; i < game.players.length; i++) {
-        const player = game.players[i];
-
-        let playerWon = false;
-        player.whichBets.forEach(bet => {
-            if (game.winningBets.indexOf(bet) !== -1) {
-                playerWon = true;
-            }
-        })
-
-        if (playerWon) {
-            player.outcome = 'won';
-        }
-        else {
-            player.outcome = 'lost';
-        }
-
-        player.wonAmount = calculateWinnings(player);
-
-        axios.get(`${process.env.HOME_URL}/api/postgre/?action=add_credits&session_id=${player.session_id}&credits=${player.wonAmount}&game=roulette&outcome=${player.outcome}`).then(postgreRes => {
-            if (postgreRes.data?.success) {
-                player.credits = postgreRes.data?.credits;
-            }
-        });
-    }
-}
-
-function resetGame() {
-    game.magicNumber = -1;
-    game.winningBets = [];
-    game.status = '_1_ongoing_timer';
-
-    game.players.forEach(player => {
-        player.whichBets = [];
-        player.betAmount = 0;
-        player.wonAmount = 0;
-        player.coinPlaced = {
-            x: -1,
-            y: -1,                
-        },
-        player.outcome = 'none';
-        player.status = '_1_no_placed_bet';
-        player.gotResults = false;
-    })
-}
-
-function calculateWinnings(player) {
-    if (player.outcome === 'lost') return 0;
-
-    let bets = player.whichBets;
-    let bet = player.betAmount;
-
-    if (bets[0] === 'Even' || bets[0] === 'Odd') return 2 * bet;
-    else if (bets[0] === 'Red' || bets[0] === 'Black') return 2 * bet;
-    else if (bets[0].includes('Remainder')) return 3 * bet;
-    else if (bets[0] === '1-12' || bets[0] === '13-24' || bets[0] === '25-36') return 3 * bet;
-    else if (bets[0] === '1-18' || bets[0] === '19-36') return 2 * bet;
-    else if (bets.length === 4) return 9 * bet;
-    else if (bets.length === 2) return 18 * bet;
-    else if (bets.length === 1) return 36 * bet;
-
-    return 0;
-}
+import { getWinningBets } from './calculateWinnings'
 
 (function() {
@@ -151,49 +42,4 @@
     game.winningBets = [];
     game.players = [];
-}
-
-function addPlayer(session_id, name) {
-    if (game.players.map(e=>e.session_id).indexOf(session_id) === -1) {
-        game.players.push({
-            session_id: session_id,
-            name: name,
-            whichBets: [],
-            coinPlaced: {
-                x: -1,
-                y: -1,                
-            },
-            credits: -1,
-            betAmount: 0,
-            wonAmount: 0,
-            status: '_1_no_placed_bet',
-            outcome: 'none',
-            gotResults: false,
-        })
-    }
-}
-
-export function getPlayer(session_id) {
-    const playerIdx = game.players.map(e=>e.session_id).indexOf(session_id);
-
-    if (playerIdx !== -1) {
-        return {
-            success: true,
-            player: game.players[playerIdx],
-        }
-    }
-
-    return {
-        success: false,
-        player: {...samplePlayer},
-    };
-}
-
-export function restrictGameInfo() {
-    const restrictedPlayers = game.players.map(player=>({...player, session_id: ""}))
-
-    return {
-        ...game,
-        players: restrictedPlayers,
-    }
 }
 
