end condition redefined and added extra begin/end functions