finished most of the functionality