general refactor. next is to implement file IO