added features, fixed code