merged with ruslan's code