Litte fixes and refactoring