refactor to better handle collisions etc