Much simpler code that uses tab checks instead