Fix and optimize a few things