Profile handling bug fixes

Fixed a few bugs with profile handling code