cleanup code
correct prototypes
deallocate unused memory