Changed sed commands to work with OSX sed (not tested with GNU/linux sed)