cleanup and separation of functions