cleaned up code. fixed bug.