Small fixes and optimalizations