fixed many syntactical issues and variable scope issues (implicitly declared variables mostly)