Small fixes and refactoring from TODO list