Writint to log and fixing error