Adjusted to fix same way as Azils original code