Added some delegate methods, debugging, cleaner code