refactored a lot. cleaned up the code a lot.