Added the service layer logic and fixed bugs.