Cleaned up some functions, added testing, etc