Refactor and add makefile