Fixed pool bug and simplified code a bit