Work in progress, added most of the functionality.