more testing
refactor and some error handling