Account for variable layout directions

I didn’t intentionally add this to fix #2, but from reading through it quickly I think it might fix that too.