Refactors payments code