Refactored & fixed quite a few issues