Modified for my own use.