code cleanup and spec fixes