fixed bugs, and added onload behavior