moved code around a little