added logic for BIN; deleted some unused code