finished most of functions