refactor gpu code