added most of the functionality