fix error handling
refactorings

- separate some procedures to functions in polling function
- make starting polling function