Bug 1684 and 1683

Tests to 1684
https://gist.github.com/Exorades/af80d16ecb614515d101