Add some documentation
Minor code refactor