Code clean up and reduce GNU sed dependencies