Updated skeleton with code from stackoverflow answer