alanoe/refactor code

Several small code refactorings