Fixed and removed unused code