Refactored code. Updated demo page.