Refactoring & better documentation