Fixed significant errors in code