Code refactoring + some small fixes

Also example project was updated.