Cleaned up code. Now try to speed it up