Refactored to separate files and fixed JSLint errors