Fix incorrect file pool closing. Refactor tests