some cleanups/fixes. need better tests though