added function and #includes
fixed code