Completely refactor to make it more robust against changes