fixed subtle bugs