Refactored testing stuff into separate expressions and fixed some Perl dumbness