fixed the demo page and refactoring some code