refactor code based on review comments