Solving #118, #328, and #391 by amiccolis

Merging solutions by @amiccolis.