Finished and commented code. Working without bonus features.