updated algorithms and made minor cleanup