fixed scheme bug #24 identified by @mahemoff and general cleanup