refactor a bit, no functional changes