Changed a few functions, to avoid repeated code