Added documentation and made stuff more readable