merged with fixes; functional