refactoring

- removed level of nesting
- return early
- got rid of goto-statement