Added a delegate protocol and some fixes