Fixed up setup and end functions