Fixed border issue
Fixed double-back bug and added unit tests