refatoring of last step code