Fix bug where shifts on different days were merged

Also lots of refactoring.