Fix weird output
Optimize and tweak