Some new test; minor bug fixes; added context management for application entity (probably should refactor it later on)