Fix issue with previousElementSibling

Also adds a test to ensure no more silly bugs