small fixes and refactor