     request.then successHandler, failureHandler
 
   successHandler = (response) ->
-    response.data
+    return response.data
 
   failureHandler = (response) ->
     console.error 'error getting the os list'
     return
 
-  {
+  return {
     getList: getList
     post: post
     put: put
     delete: deletea
   }
+
+#------------------------------------------------------------------------------#
+#--------------------------- Socket.io Factory --------------------------------#
+#------------------------------------------------------------------------------#
+
 app.factory 'socket', ->
   url = location.origin + '/vm'
   socket = io.connect(url)
-  socket
+  return socket
+
+#------------------------------------------------------------------------------#
+#--------------------------- Homepage controller ------------------------------#
+#------------------------------------------------------------------------------#
+
 app.controller 'HomeController', ($scope, $mdSidenav, os, socket, $rootScope, $mdDialog, $mdToast) ->
 
+  # TODO: timer directive
   timerToString = (timer) ->
     minutes = '' + Math.floor(timer / 60)
     seconds = '' + timer % 60

  console.log codeConverter

  initializeSocket = ->
    `var canvas`
    canvas = document.getElementById('screen')
    canvas.tabIndex = 1000
    ctx = canvas.getContext('2d')

  os.getList().then (osList) ->
    $scope.osList = osList
    return

  socket.on 'available-sessions', (data) ->
    $scope.sessionsAvailable = data.sessions
    $scope.$apply()

  socket.on 'session-timer', (data) ->
    $scope.timer = timerToString(data.timer)

  socket.on 'session-expired', ->
    $mdToast.show $mdToast.simple().content('Session expired!').position('right bottom').hideDelay(2000)
    $scope.vmIsRunning = false
    $scope.title = 'Select an OS'

  $scope.toggleSidenav = (menuId) ->
    $mdSidenav(menuId).toggle()

  $scope.title = 'Select an OS'

