bug fixing and deleting dead code