Cleaned up the javascript to use a more oop and module format