Added real code after (a lot of) optimization