More advanced version with lists and additional checking