prepared objective function - so far it seems to work