Simpler version of code submitted by Vadiok

Signed-off-by: Jason Carney <jason@dashmedia.com.au>