Merging of Richard's / Marcel's code & adding in fixes for tickets #642 / #640