Added code to make borders look neater, fixed a few bugs