Fixed detection with pooling.
Started cleaning up a bit.