fixed warnings
fixed memory leak
added function prototypes