Extended version with lot of test business logic. Will not serve generic purpose.