A less hacky solution