Fixed some errors
added selection code