Proper indentation and formatting will help you avoid bugs big time. You can checkout some sublime plugins that help automate this for you