Refactor code

General cleanup