Cleaner implementation, easier to follow
Also added vague documentation.