Added return value for functions; Fixed some bugs