Bug fixes from original author