made some of the changes suggested by Nic. Still requires more work