migrated to groovy.
updated preconditions to check for nulls.