Fixed issue #1. Also some cleanup.