Added comments and moved size determination into its own method for easier testing