refactor code into separate files; fix toJs tabbing