Refactor the gun code