greatly simplifying the process as suggested by joeferner