Implemented all functions although does not compile at the moment. Will revise shortly.