based on xrosecky's repo