Update code written 2 years ago with bugfixed