This piece definitely needs some unit testing :)