fixed stupidly written function