fixed bug and further cleanups.