refactors a bit