add better error handling
remove unused stuff
adjust a bit