First (inefficient?) implementation seems to be working