Added write calling function
Added log file writing