Added most of the functionality