code cleanup and fixed some php notices