Fixed bugs; extended tests