added border and some code cleanup / refactoring