Refactored code + writen documentation