Fix some weird issues and removed unused code