code clean up and little fixes