fixed several bugs introduced in last commit