modified for testing use only
improved version