refactor code and add pending testing