Removed unused code, fixed a bug