Bug fixes and deleting useless code