Refactor code into modules