Fixed scoping, added better errors, added more symatic checking