added error handling, removed some new lines