Fix queued 'after' functions, sort arrays correctly, fix for loops