refactored the code in demo project