Added implementation of some functions. Fixed issues with some functions.