fixed some bugs; created flag for length overflow

still need to do something with this flag?