updated code from 9-21-2014