NOTE: This method is now slightly refactored from before.