Bug, bug, bug in simple function