code cleanup and change ctx = this to self = this