Made several changes to make more generic.