Updated Delegate and cleaned up code