Convert extract() into a standalone utility