Moved functions to appropriate position and fixed/synced with README.md.