Refactor - clean up code and add comments