Ready for code review... major refactoring to be compatable with python 2.7