Fix NullPointerException when check for free space fails;
Remove duplicate code in createWhereClause functions with different signatures.