add some payment functions and refactor util functions