Bug fixes by Michael Gruenstaeudl on 2014.12.15 (see commented lines)