Code refactoring

Separated implementation into multiple JS files