refactored into multiple files and moved into javascript directory