cleaned up some functions, improved routing