removes self and optimizes code