refactor code to make it extensible