This should works much faster and is more flexibile