Added a 'type' function for accurate type checking in JS
Made the code a lot more readable
Added better comments