Fixing some bugs on sequence calculation