Changed a few small things, see code for details.