refactor a bit for clarity