refactored pay function and removed directive