removed print messages
better error handling