more bugs with using variable to encapsulate functions