Moved logic from client app