Refactored some variables and function name. Removed some dev code. Changed the style a bit.