fixed code bugs on pageload