Fixed cmake and added optimizations