Fixup and optimize, working 100%