Add notes
Code refactoring; some fixes