Removed duplicate echos and replaced with log function