Properly fix offset bug and add test