Added some optimization corrections based on Ignacy suggestions.