Removed unused code plus some more tweaks