refactor merchant code a bit