Fixed debug errors improved code