Fix some ApplicationPool bugs and fix its unit tests