moved code around so it's nicer