Edited sed command, and a few tidyups