Pass needed objects to functions

Erm, it works now.