added optimizations, some GCC specific flags and improved the code a bit