added more functions, cleaned up code