move self variable initialization to top of function