cleaned up the code in response to Fleur comments