Bug fixes and some CS fixes