modified version to work with customized format.