- improve organization and improve some error handling