added dependency injection and did some other things