Parallel scan algorithm

Bug-fix & clean-up