Modified to not try to read from stdin. It was screwing up using it from Ant. Made logic less redundant.