Finished most of functions