Minor refactoring, added docs