Optimizations, added debug flag, indentation