Adding bad element stripping and minor cleanup