Change code structure, use delegate instead of closure for better readibility