merged with old code