Code refactor, some documentation