Pretty print and minor optmizations